// 关于托盘的js
export  const huizhi_tray_focus = (zhanbi,img_element) => {
    const canvas = document.createElement("canvas");
    canvas.width = 32;
    canvas.height = 32;
    const ctx = canvas.getContext("2d");
    const centerX = 16;
    const centerY = 16;
    const radius = 13; // 半径
    const startAngle = -0.5 * Math.PI; // 12点位置
    const endAngle = startAngle + (zhanbi * 2 * Math.PI) / 100; // zhanbi%的圆环
  
    // 清空画布（透明背景）
    ctx.clearRect(0, 0, canvas.width, canvas.height);
  
    // 设置圆环颜色和线宽
    ctx.strokeStyle = "red";
    ctx.lineWidth = 5;
  
    // 绘制圆环
    ctx.beginPath();
    ctx.arc(centerX, centerY, radius, startAngle, endAngle, false);
    ctx.stroke();
  
    // Load the user image and draw it in the center
  
    const imgSize = 16;
    ctx.drawImage(img_element, 8, 8, 16, 16);
  
    // Save the canvas as a PNG
    const dataUrl = canvas.toDataURL("image/png").split(",")[1];
    // console.log(canvas.toDataURL("image/png"));
    // base64转换为Uint8Array
    return base64ToUint8Array(dataUrl);
  };
  
 export const huizhi_tray_break = (zhanbi,img_break_element) => {
    const canvas = document.createElement("canvas");
    canvas.width = 32;
    canvas.height = 32;
    const ctx = canvas.getContext("2d");
    const centerX = 16;
    const centerY = 16;
    const radius = 13; // 半径
    const startAngle = -0.5 * Math.PI; // 12点位置
    const endAngle = startAngle + (zhanbi * 2 * Math.PI) / 100; // zhanbi%的圆环
  
    // 清空画布（透明背景）
    ctx.clearRect(0, 0, canvas.width, canvas.height);
  
    // 设置圆环颜色和线宽
    ctx.strokeStyle = "green";
    ctx.lineWidth = 5;
  
    // 绘制圆环
    ctx.beginPath();
    ctx.arc(centerX, centerY, radius, startAngle, endAngle, false);
    ctx.stroke();
  
    // Load the user image and draw it in the center
  
    const imgSize = 16;
    ctx.drawImage(img_break_element, 8, 8, 16, 16);
  
    // Save the canvas as a PNG
    const dataUrl = canvas.toDataURL("image/png").split(",")[1];
    // console.log(canvas.toDataURL("image/png"));
    // base64转换为Uint8Array
    return base64ToUint8Array(dataUrl);
  };
  
 export const base64ToUint8Array = (str_64) => {
    const binaryString = atob(str_64);
    const len = binaryString.length;
    const array8 = new Uint8Array(len);
  
    // 将每个字符转换为对应的字节
    for (let i = 0; i < len; i++) {
      array8[i] = binaryString.charCodeAt(i);
    }
  
    return array8;
  };